﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Media;

namespace FierceWar
{
	public class MainMenuScreen : MenuScreen
	{
		// Menu entries.
		private MenuEntriesManager _menuEntriesManager;
		private MenuEntry _playGame;
		private MenuEntry _createMap;
		private MenuEntry _option;
		private MenuEntry _help;
		private MenuEntry _about;
		private MenuEntry _quit;
		
		private Rectangle _outerRectangle;
		private Rectangle _innerRectangle;

		public MainMenuScreen(
			GameResources resources, List<EventHandler> screenEvents)
			: base(resources, screenEvents)
		{
			_playGame = new MenuEntry(resources, "Play Game", 1500.0f, 100.0f);
			_createMap = new MenuEntry(resources, "Create Map", 800.0f, 100.0f);
			_option = new MenuEntry(resources, "Option", 1500.0f, 100.0f);
			_help = new MenuEntry(resources, "Help", 1500.0f, 100.0f);
			_about = new MenuEntry(resources, "About", 800.0f, 100.0f);
			_quit = new MenuEntry(resources, "Quit", 0.0f, 0.0f);

			_menuEntriesManager = new MenuEntriesManager(resources, screenEvents);
			_menuEntriesManager.MenuEntries.Add(_playGame);
			_menuEntriesManager.MenuEntries.Add(_createMap);
			_menuEntriesManager.MenuEntries.Add(_option);
			_menuEntriesManager.MenuEntries.Add(_help);
			_menuEntriesManager.MenuEntries.Add(_about);
			_menuEntriesManager.MenuEntries.Add(_quit);
			_menuEntriesManager.OriginY = 150.0f;
			_menuEntriesManager.DistanceInterval = 50.0f;
			_menuEntriesManager.InitializePositions();
			
			_outerRectangle = new Rectangle(
					(Resources.GraphicsDevice.Viewport.Width - 300) / 2,
					(Resources.GraphicsDevice.Viewport.Height - 350) / 2,
					300, 350);
			_innerRectangle = new Rectangle(
					(Resources.GraphicsDevice.Viewport.Width - 280) / 2,
					(Resources.GraphicsDevice.Viewport.Height - 330) / 2,
					280, 330);
		}

		public override void Update(GameTime gameTime)
		{
			base.Update(gameTime);

			_menuEntriesManager.Update(gameTime);
		}
		
		public override void Draw(GameTime gameTime)
		{
			base.Draw(gameTime);

			Resources.SpriteBatch.Draw(Resources.BackgroundTexture,
				FullScreen, Color.White);
			Resources.SpriteBatch.Draw(Resources.BlankTexture,
				_outerRectangle,
				Color.Black * 0.35f);
			Resources.SpriteBatch.Draw(Resources.BlankTexture,
				_innerRectangle,
				Color.Black * 0.35f);
			_menuEntriesManager.Draw();
		}
	}
}
